﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:MetroWPF.Controls"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib">
    <Style TargetType="{x:Type local:ToggleSwitch}">
        <Setter Property="Foreground" Value="{DynamicResource ToggleSwitchForegroundThemeBrush}" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="OnContent" Value="On" />
        <Setter Property="OffContent" Value="Off" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontWeight" Value="SemiBold" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="MinWidth" Value="154" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ToggleSwitch}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchCurtain">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchCurtainPointerOverBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchTrackPointerOverBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbPointerOverBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbPointerOverBorderThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchCurtain">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchCurtainPressedBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchTrackPressedBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbPressedBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbPressedForegroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="HeaderContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchHeaderDisabledForegroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="OffContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchDisabledForegroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="OnContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchDisabledForegroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="OuterBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchOuterBorderDisabledBorderThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="InnerBorder">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchTrackDisabledBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbDisabledBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="SwitchKnob">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchThumbDisabledBorderThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="SwitchCurtain">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{DynamicResource ToggleSwitchCurtainDisabledBackgroundThemeBrush}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ToggleStates">
                                <VisualState x:Name="Dragging">
                                </VisualState>
                                <VisualState x:Name="Off">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.07" To="-44" Storyboard.TargetProperty="X" Storyboard.TargetName="CurtainTranslateTransform" />
                                        <DoubleAnimation Duration="0:0:0.07" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="KnobTranslateTransform" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="On">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0:0:0.07" To="0" Storyboard.TargetProperty="X" Storyboard.TargetName="CurtainTranslateTransform" />
                                        <DoubleAnimation Duration="0:0:0.07" To="38" Storyboard.TargetProperty="X" Storyboard.TargetName="KnobTranslateTransform" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="ContentStates">
                                <VisualState x:Name="OffContent">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="OffContentPresenter" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="OffContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="OnContent">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="OnContentPresenter" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible" Storyboard.TargetName="OnContentPresenter">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualWhite" />
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="FocusVisualBlack" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unfocused" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <ContentControl x:Name="HeaderContentPresenter" Grid.ColumnSpan="2" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Foreground="{DynamicResource ToggleSwitchHeaderForegroundThemeBrush}" FontWeight="Medium" Margin="6" />
                            <Grid Margin="{TemplateBinding Padding}" Grid.Row="1">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="7" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ContentControl x:Name="OffContentPresenter" ContentTemplate="{TemplateBinding OffContentTemplate}" Content="{TemplateBinding OffContent}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="6,5,0,16" MinWidth="65" Opacity="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                <ContentControl x:Name="OnContentPresenter"  ContentTemplate="{TemplateBinding OnContentTemplate}" Content="{TemplateBinding OnContent}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="False" Margin="6,5,0,16" MinWidth="65" Opacity="0" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                <Grid Background="Transparent" Grid.Column="2">
                                    <Grid x:Name="SwitchKnobBounds" Height="19" Margin="13,5,13,16">
                                        <Border x:Name="OuterBorder" BorderBrush="{DynamicResource ToggleSwitchOuterBorderBorderThemeBrush}" BorderThickness="2">
                                            <Border x:Name="InnerBorder" BorderBrush="{DynamicResource ToggleSwitchTrackBorderThemeBrush}" BorderThickness="1" ClipToBounds="True" Background="{DynamicResource ToggleSwitchTrackBackgroundThemeBrush}">
                                                <Rectangle x:Name="SwitchCurtain" Fill="{DynamicResource ToggleSwitchCurtainBackgroundThemeBrush}" Width="44">
                                                    <Rectangle.RenderTransform>
                                                        <TranslateTransform x:Name="CurtainTranslateTransform" X="-44" />
                                                    </Rectangle.RenderTransform>
                                                </Rectangle>
                                            </Border>
                                        </Border>
                                        <Rectangle x:Name="SwitchKnob" Fill="{DynamicResource ToggleSwitchThumbBackgroundThemeBrush}" HorizontalAlignment="Left" Stroke="{DynamicResource ToggleSwitchThumbBorderThemeBrush}" StrokeThickness="1" Width="12">
                                            <Rectangle.RenderTransform>
                                                <TranslateTransform x:Name="KnobTranslateTransform" />
                                            </Rectangle.RenderTransform>
                                        </Rectangle>
                                        <Rectangle x:Name="FocusVisualWhite" Margin="-3" Opacity="0" Stroke="{DynamicResource FocusVisualWhiteStrokeThemeBrush}" />
                                        <Rectangle x:Name="FocusVisualBlack" Margin="-3" Opacity="0" Stroke="{DynamicResource FocusVisualBlackStrokeThemeBrush}" />
                                    </Grid>
                                    <Thumb x:Name="PART_SwitchThumb">
                                        <Thumb.Template>
                                            <ControlTemplate TargetType="Thumb">
                                                <Rectangle Fill="Transparent" />
                                            </ControlTemplate>
                                        </Thumb.Template>
                                    </Thumb>
                                </Grid>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>